#include <zenilib.h>
#include "Projectile.h"

Projectile::Projectile(Vector2 pos_, bool flipped_, WeaponType type_, Player *firedBy_) :
	GameObject(pos_),
	type(type_),
	firedBy(firedBy_),
	textureChangeElapsedTime(0)
{
	flipped = flipped_;
	switch (type){
		case UZI:
			damage = 4;
			setScale(Vector2(10, 5));
			setVel(Vector2(flipped ? -800 : 800, 0));
			addTexture("Bullet");

			break;
		case LASER:
			damage = 8;
			setScale(Vector2(30, 10));
			setVel(Vector2(flipped ? -800 : 800, 0));
			addTexture("Laser");
			break;
		case SHURIKEN:
			damage = 4;
			setScale(Vector2(25, 25));
			setVel(Vector2(flipped ? -800 : 800, 0));
			setRotVel(flipped ? 4 * pi : -4 * pi);
			addTexture("Shuriken");
			break;
		case BIGGUN:
			damage = 20;
			setScale(Vector2(60, 15));
			setVel(Vector2(flipped ? -600 : 600, 0));
			addTexture("Rocket1");
			break;
	}
}

void Projectile::update(const float & timestep)
{
	if (type == BIGGUN){
		const float maxElapsed = 0.05f;
		textureChangeElapsedTime += timestep;
		if (textureChangeElapsedTime > maxElapsed){
			textureChangeElapsedTime = 0;
			if (textures[0] == "Rocket1"){
				textures[0] = "Rocket2";
			}
			else{
				textures[0] = "Rocket1";
			}
		}
	}
	GameObject::update(timestep);
}